package finalproject.controller.commands;

import finalproject.model.player.Player;
import finalproject.model.rooms.Direction;
import finalproject.model.rooms.Room;
import finalproject.view.StringManager;

/**
 * the go command
 * @author Buisson Kevin
 *
 */
public class GoCommand extends Command {

	/**
	 * 
	 * @param player the player issuing the command
	 * @param args the command argument
	 */
	public GoCommand(Player player, String[] args)
	{
		super(player, args);
	}

	@Override
	public boolean process()
	{
		// No light
		if (!getPlayer().getCurrentRoom().isLighted())
		{
			StringManager.outPut("canttakeitnolight");
			return false;
		}

		// No direction
		if (!hasSecondWord())
			// if there is no second word, we don't know where to go...
			StringManager.outPut("nodirection");

		Direction direction;
		try
		{
			direction = Direction.valueOf(getSecondWord().toUpperCase());
		}
		catch (Exception e)
		{
			// Bad direction
			StringManager.outPut("gowhere");
			return false;
		}

		// Try to leave current room.
		Room nextRoom = getPlayer().getCurrentRoom().getExit(direction);

		// No door
		if (nextRoom == null)
			StringManager.outPut("nodoor");
		// Change room
		else if (getPlayer().getIn(nextRoom))
		{
			
			StringManager.outPutText(getPlayer().getCurrentRoom().toString() + "\n"
					+ getPlayer().getCurrentRoom().getExitString());
			getPlayer().getCurrentRoom().prepareActivity(getPlayer());
			// Changed room successfully
			return true;
		}
		else
		{
			// Can't leave
			StringManager.outPut("cantleave");
		}

		return false;
	}
}
